package com.mywang.weitravel.modules.footprint;

import com.mywang.weitravel.base.BasePresenter;
import com.mywang.weitravel.model.FootprintListBean;
import com.mywang.weitravel.net.RetrofitHelper;
import com.mywang.weitravel.net.RxSchedulers;
import com.mywang.weitravel.net.VObserver;

import java.util.HashMap;

/**
 * Created by wangmingyun on 2019/12/5.
 */
public class FootprintPresenter extends BasePresenter<FootprintContract.View> implements FootprintContract.Presenter {

    public FootprintPresenter(FootprintContract.View view) {
        super(view);
    }

    @Override
    public void getFootPrintList(int page) {
        HashMap<String, String> params = new HashMap<>();
        params.put("page", String.valueOf(page));

        RetrofitHelper.getInstance().getServer()
                .getFootprintList(params)
                .compose(RxSchedulers.applySchedulers())
                .as(bindToLife())
                .subscribe(new VObserver<FootprintListBean>() {
                    @Override
                    protected void onSuccess(FootprintListBean listBeans) {
                        mView.getListSuccess(listBeans);
                    }

                    @Override
                    protected void onFailure(int code, String message, boolean isShowMsg) {
                        super.onFailure(code, message, isShowMsg);
                        mView.getListError();
                    }
                });
    }

    @Override
    public void markFootPrint(int position, String id) {
        mView.showLoading();
        RetrofitHelper.getInstance().getServer()
                .likeMark(id)
                .compose(RxSchedulers.applySchedulers())
                .as(bindToLife())
                .subscribe(new VObserver<Object>() {
                    @Override
                    protected void onSuccess(Object o) {
                        mView.markFootPrintSuccessful(position);
                    }

                    @Override
                    public void onComplete() {
                        super.onComplete();
                        mView.hideLoading();
                    }
                });
    }
}
